package com.akuhome.resource.job;

import com.akuhome.resource.enums.ResultEnum;
import com.akuhome.resource.exception.ResourceException;
import com.akuhome.resource.service.check.ProjectCheckService;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;


@Component
@DisallowConcurrentExecution
public class AddCheckJob extends QuartzJobBean {

    Logger logger = LoggerFactory.getLogger(AddCheckJob.class);

    @Autowired
    ProjectCheckService projectCheckService;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobDataMap dataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        String uid = dataMap.getString("uid");
        if(uid != null){
            logger.info("正在为uid为 "+uid+" 的项目生成结算报表");
            projectCheckService.initCheck(uid);
            logger.info("uid为 "+uid+" 的项目结算报表已生成完毕");
        }else{
            throw new ResourceException(ResultEnum.DATA_MAP_ERROR);
        }
    }
}
